<!DOCTYPE html>
<html lang=>
    <head>
        <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta http-equiv="cache-control" content="no-cache" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta name="format-detection" content="telephone=no" />
<meta name="author" content='yi_Xu' />
<meta name="description" content='现在整个网站是部署在阿里云上的，但基础代码还是放在 github 上，这样通过 github 的 webhook 可以实现自动推送，但是本地生成的文件还是需要几步更新，推送到 github 的上的，所以写了一个脚本来进行，最后一步的生成和推送。' />
<meta name="keywords" content='web,python,blog,batch' />
<meta name="generator" content="Hugo 0.80.0" />
<meta property="og:url" content='https://www.yixuju.cn/programming/batch/hugo-push/' />
<meta property="og:title" content='编写 bat 批处理脚本文件来设置自动推送' />
<meta property="og:description" content='现在整个网站是部署在阿里云上的，但基础代码还是放在 github 上，这样通过 github 的 webhook 可以实现自动推送，但是本地生成的文件还是需要几步更新，推送到 github 的上的，所以写了一个脚本来进行，最后一步的生成和推送。' />
<meta property="og:site_name" content='逸絮居' />
<meta property="og:image" content='https://www.yixuju.cn/img/background.jpg' />
<meta property="og:locale" content='zh-CN' />
<meta property="fb:app_id" content='198934840692875' />
<meta property="fb:admins" content='' />
<meta itemprop="name" content='编写 bat 批处理脚本文件来设置自动推送' />
<meta itemprop="description" content='现在整个网站是部署在阿里云上的，但基础代码还是放在 github 上，这样通过 github 的 webhook 可以实现自动推送，但是本地生成的文件还是需要几步更新，推送到 github 的上的，所以写了一个脚本来进行，最后一步的生成和推送。' />
<meta itemprop="image" content='https://www.yixuju.cn/img/background.jpg' />
<meta name="twitter:card" content='summary' />

<meta name="twitter:site" content='' />

<meta name="twitter:creator" content='' />
<meta name="twitter:title" content='编写 bat 批处理脚本文件来设置自动推送' />
<meta name="twitter:description" content='现在整个网站是部署在阿里云上的，但基础代码还是放在 github 上，这样通过 github 的 webhook 可以实现自动推送，但是本地生成的文件还是需要几步更新，推送到 github 的上的，所以写了一个脚本来进行，最后一步的生成和推送。' />
<meta name="twitter:image" content='https://www.yixuju.cn/img/background.jpg' />
<title>编写 bat 批处理脚本文件来设置自动推送 | 逸絮居 </title>
<link rel="canonical" href=https://www.yixuju.cn/programming/batch/hugo-push/ />
<link rel="icon" type="image/x-icon" href=/favicon.ico />
<link rel="icon" type="image/png" href=/favicon.png />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/index.xml" />
<link rel="stylesheet" href=/css/style.min.css />
<script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/clipboard@2/dist/clipboard.min.js"></script>
<script src=/js/custom.min.js></script>
        
        
    </head>
    <body>
        <div>
    <a href=/about>
        <img id="mobile-avatar" class="mobile animated zoomIn" src=/img/avatar.jpg alt=yi_Xu>
    </a>
</div>
<div id="mobile-navbar" class="mobile">
    <div class=" button mobile-navbar">
        <span>菜单</span>
    </div>
</div>
<div id="gotop" class="mobile gotop">
    <div class=" button mobile-navbar">
        <span>置顶</span>
    </div>
</div>
<div id="jquery-menu" class="mobile">
    <ul id="mobile-menu">
        
            
                <li>
                    <a href= />
                        首页
                    </a>
                </li>
            
        
            
                
                    <li>
                        <a href=/programming/>编程体验</a>
                    </li>
                
                    <li>
                        <a href=/other/>其他分享</a>
                    </li>
                
                    <li>
                        <a href=/blog/>生活感悟</a>
                    </li>
                
            
        
            
                <li>
                    <a href= /page/about/>
                        关于
                    </a>
                </li>
            
        
            
                <li>
                    <a href= /page/cards/>
                        卡片集
                    </a>
                </li>
            
        
    
    <li id="mobile-toc-title">目录<i id="down-up" class="icon-double-angle-down"></i>
    <div id="mobile-toc" class="mobile"><nav id="TableOfContents">
  <ul>
    <li><a href="#一些说明">一些说明</a></li>
    <li><a href="#提供英文版以消除编码方式影响">提供英文版以消除编码方式影响</a></li>
  </ul>
</nav></div></li>

</div>
        <header>
    <div id="header">
        <a id = "site-title" href= https://www.yixuju.cn >
            <span>逸絮居</span>
        </a>
        <ul id="header-menu">
            <li>
                <a class="gotop" href="#">置顶</a>
            </li>
            
            
                <li>
                    <a href= / >
                        首页
                    </a>
                </li>
            
                <li>
                    <a href= /page/archieves/ >
                        归档
                    </a>
                </li>
            
                <li>
                    <a href= /page/about/ >
                        关于
                    </a>
                </li>
            
                <li>
                    <a href= /page/cards/ >
                        卡片集
                    </a>
                </li>
            
        </ul>
    </div>
</header>

        <div id="container">
            <section id="main">
                
    <article id="post" class="card">
    <div id="post-title">
        <h1>编写 bat 批处理脚本文件来设置自动推送</h1>
    </div>
    <div id="post-cotent">
        <p>现在整个网站是部署在阿里云上的，但基础代码还是放在 github 上，这样通过 github 的 webhook 可以实现自动推送，但是本地生成的文件还是需要几步更新，推送到 github 的上的，所以写了一个脚本来进行，最后一步的生成和推送。</p>
<blockquote>
<p><strong>注意</strong>：bat 批处理脚本在 <a href="https://www.yixuju.cn/programming/batch/hugo-push-1/">《通过复制 git 信息提交网站更新 commit》</a> 中完成了新的更新配置，以便将每次的更新记录在 github commit 信息中。</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-batch" data-lang="batch"><span class="p">@</span><span class="k">echo</span> off
<span class="k">set</span> <span class="nv">pan</span><span class="p">=</span>.\public\
<span class="k">set</span> <span class="nv">repo</span><span class="p">=</span>https://github.com/yi-Xu-0100/www.yixuju.cn.git
<span class="k">set</span> <span class="nv">branch</span><span class="p">=</span>master
<span class="k">if</span> <span class="k">exist</span> <span class="nv">%pan%</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;清除 public 文件夹&#34;</span>
    <span class="k">rd</span> /S /Q <span class="nv">%pan%</span>
    <span class="k">echo</span> <span class="s2">&#34;重新执行Hugo命令生成站点&#34;</span>
    hugo
<span class="p">)</span> <span class="k">else</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;未发现 public 文件夹&#34;</span>
    <span class="k">echo</span> <span class="s2">&#34;重新执行 Hugo 命令生成站点&#34;</span>
    hugo
<span class="p">)</span>
<span class="k">if</span> <span class="k">exist</span> <span class="nv">%pan%</span> <span class="p">(</span>
    <span class="k">cd</span> <span class="nv">%pan%</span>
    <span class="k">echo</span> <span class="s2">&#34;初始化 git&#34;</span>
    git init
    git add --all
    git commit -m <span class="s2">&#34;update site at </span><span class="nv">%time%</span><span class="s2">&#34;</span>
    <span class="k">echo</span> <span class="s2">&#34;设置远程库并推送&#34;</span>
    git remote add origin <span class="nv">%repo%</span>
    git push -f origin master:master -v
<span class="p">)</span> <span class="k">else</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;未找到 public 文件夹，疑似 hugo 命令未成功！&#34;</span>
<span class="p">)</span>
<span class="k">pause</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="一些说明">一些说明</h2>
<p>这个脚本运行可能会碰到一些问题，本质上说，需要一定的条件：</p>
<ul>
<li>完成免密码与 github 链接。</li>
<li>脚本中的路径需要自己修改设置。</li>
<li>仅支持 windows 系统。【 win10 系统测试通过】</li>
</ul>
<h2 id="提供英文版以消除编码方式影响">提供英文版以消除编码方式影响</h2>
<p>考虑到站点源文件统一使用 UTF-8 编码方式，而 windows 默认编码方式为 gbk ，造成中文在 cmd 中和编辑器中总有一个显示不正确，所以将脚本中文字替换成英文，以避免编码方式的影响。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-batch" data-lang="batch"><span class="p">@</span><span class="k">echo</span> off
<span class="k">set</span> <span class="nv">pan</span><span class="p">=</span>.\public\
<span class="k">set</span> <span class="nv">repo</span><span class="p">=</span>git@github.com:yi-Xu-0100/www.yixuju.cn.git
<span class="k">set</span> <span class="nv">branch</span><span class="p">=</span>master
<span class="k">if</span> <span class="k">exist</span> <span class="nv">%pan%</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;clean public directory&#34;</span>
    <span class="k">rd</span> /S /Q <span class="nv">%pan%</span>
    <span class="k">echo</span> <span class="s2">&#34;Hugo again for new site&#34;</span>
    hugo
<span class="p">)</span> <span class="k">else</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;can not find public directory&#34;</span>
    <span class="k">echo</span> <span class="s2">&#34;Hugo again for new site&#34;</span>
    hugo
<span class="p">)</span>
<span class="k">if</span> <span class="k">exist</span> <span class="nv">%pan%</span> <span class="p">(</span>
    <span class="k">cd</span> <span class="nv">%pan%</span>
    <span class="k">echo</span> <span class="s2">&#34;git init and commit&#34;</span>
    git init
    git add --all
    git commit -m <span class="s2">&#34;update site at </span><span class="nv">%time%</span><span class="s2">&#34;</span>
    <span class="k">echo</span> <span class="s2">&#34;set remote repository and push forcely&#34;</span>
    git remote add origin <span class="nv">%repo%</span>
    git push -f origin master:master -v
<span class="p">)</span> <span class="k">else</span> <span class="p">(</span>
    <span class="k">echo</span> <span class="s2">&#34;can not find public directory, hugo fail!&#34;</span>
<span class="p">)</span>
<span class="k">pause</span>
</code></pre></td></tr></table>
</div>
</div>
    </div>
    <div id="copyright" class="card">

    <div><span> 文章标题：编写 bat 批处理脚本文件来设置自动推送</span>
    </div>


    <div><span> 文章作者：yi_Xu</span>
    </div>


    <div>文章标签：
      <a href="https://www.yixuju.cntags/bat/">#bat&nbsp</a>
      <a href="https://www.yixuju.cntags/cmd/">#cmd&nbsp</a>
    </div>



    <div>创建时间：<time datetime=2019-01-22></time>2019-01-22 | 最新更新于：<time datetime=2019-01-22></time>2019-01-22
    </div>

    <div>原始链接：https://www.yixuju.cn/programming/batch/hugo-push/<span class="copy-path" title="点击复制文章链接" data-clipboard-demo="" data-clipboard-action="copy" data-clipboard-text='https://www.yixuju.cn/programming/batch/hugo-push/' aria-label="复制成功！"><i class="icon-copy"></i></span>
    </div>

    <div>许可协议：<a rel="license nofollow" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank rel="nofollow">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </div>

</div>
</article>

    
        <div class=" card pagination">
        
            
            <a class="button next-page" href= /programming/batch/hugo-push-1/ title=通过复制&#32;git&#32;信息提交网站更新&#32;commit>
                下一页
            </a>
            
        </div>
    


            </section>
            <section id="sidebar">
                
    <aside class="sidebar">
  <div id="avatar" class="card">
      <a href=/page/about>
          <img class="animated zoomIn" id="avatar-img" src=/img/avatar.jpg alt=yi_Xu>
      </a>
      <div id="motto">
          <span>品水如酒，愚醉……</span>
      </div>
  </div>
  <div id="categories" class="card">
      <div class="card-title sidebar-title">文章分类</div>
      
      <li class="category">
          <a href=/programming/>编程体验</a>
          
              
                  <ol class="subcategory">
                      <a href=/programming/batch/>batch</a>
                  </ol>
              
                  <ol class="subcategory">
                      <a href=/programming/python/>python</a>
                  </ol>
              
          
      </li>
      
      <li class="category">
          <a href=/other/>其他分享</a>
          
      </li>
      
      <li class="category">
          <a href=/blog/>生活感悟</a>
          
      </li>
      
  </div>
  <div id="communication" class="card">
    <div class="card-title sidebar-title">联系方式</div>
    
    <li class="communication-list">
      <span>GitHub: <a href="https://github.com/yi-Xu-0100" target="_blank" rel="nofollow">@yi-Xu-0100</a></span>
    </li>
    
    <li class="communication-list">
      <span>TG 频道: <a href="https://t.me/yixuju_notify" target="_blank" rel="nofollow">t.me/yixuju_notify</a></span>
    </li>
    
    <li class="communication-list">
      <span>TG 群组: <a href="https://t.me/yixuju" target="_blank" rel="nofollow">t.me/yixuju</a></span>
    </li>
    
    <li class="communication-list">
      <span>QQ 群组: <a href="https://jq.qq.com/?_wv=1027&amp;k=XKIJXRol" target="_blank" rel="nofollow">495793229</a></span>
    </li>
    
    <li class="communication-list">
      <span>联系邮箱: <a href="mailto:yi_Xu@yixuju.cn" target="_blank" rel="nofollow">yi_Xu@yixuju.cn</a></span>
    </li>
    
    <li class="communication-list">
      <span>微信公众号: <a href="" target="_blank" rel="nofollow">逸絮居</a></span>
    </li>
    
</div>
</aside>
    
    <aside class="sidebar">
        <div id="post-menu" class="card">
            <div class="card-title sidebar-title">目录</div>
            <div id="toc"><nav id="TableOfContents">
  <ul>
    <li><a href="#一些说明">一些说明</a></li>
    <li><a href="#提供英文版以消除编码方式影响">提供英文版以消除编码方式影响</a></li>
  </ul>
</nav></div>
        </div>
    </aside>


            </section>
        </div>
        <footer>
    <a  
            href="mailto:yi_Xu@yixuju.cn"
            target = "_blank"
        
        target = "_self" rel="nofollow">
            &copy; 2014 - 2022 yi_Xu
    </a>
    <i class="icon-lightbulb"></i>
    <a href="https://gohugo.io/" target="_blank" rel="nofollow">Power_by Hugo 0.80.0</a>
    <i class="icon-coffee"></i>
    <a href="https://github.com/yi-Xu-0100/hugo-theme-whiteink" target="_blank">Theme_by WhiteInk</a>
    
        <i class="icon-legal"></i>
        <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">鲁 ICP 备 17049362 号</a>
    
</footer>
    </body>
</html>